/****************************************************
          File Name:12-1_imply.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Wed 24 Dec 2014 03:03:41 PM CST
*****************************************************/

#include"12-1.h"
#include<cstring>

Cow::Cow()
{
    strcpy(name, "nobody");
    hobby = new char[4];
    strcpy(hobby, "none");
    weight = 0.0;
}

Cow::Cow(const char *nm, const char *ho, double wt)
{
    strcpy(name, nm);
    hobby = new char[strlen(ho)+1];
    strcpy(hobby, ho);
    weight = wt;
}

Cow::Cow(const Cow & c)
{
    strcpy(name, c.name);
    hobby = new char[strlen(c.hobby)+1];
    strcpy(hobby, c.hobby);
    weight = c.weight;
}

Cow::~Cow()
{
    std::cout << hobby << " --> deleted\n";
    delete [] hobby;
}

Cow & Cow::operator=(const Cow & c)
{
    if(this == &c)
        return *this;
    delete hobby;
    hobby = new char[strlen(c.hobby)+1];
    strcpy(hobby, c.hobby);
    strcpy(name, c.name);
    weight = c.weight;

    return *this;
}

void Cow::ShowCow() const
{
    using std::cout;

    cout << "Name: " << name << "\n";
    cout << "Hobby: " << hobby << "\n";
    cout << "Weight: " << weight << "\n";
}
